package com.cloud.pole.shop.service.shops.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.pole.common.util.jwt.IJWTInfo;
import com.cloud.pole.common.util.jwt.JwtTokenUtil;
import com.cloud.pole.shop.biz.goods.ShopGoodsPromotionBiz;
import com.cloud.pole.shop.biz.shops.ShopShopsComponentBiz;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsPromotion;
import com.cloud.pole.shop.model.entity.shops.ShopShopsComment;
import com.cloud.pole.shop.model.entity.shops.ShopShopsComponent;
import com.cloud.pole.shop.model.entity.shops.ShopShopsWithBLOBs;
import com.cloud.pole.shop.service.shops.ShopsComponentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class ShopsComponentServiceImpl implements ShopsComponentService {
	@Autowired
	 private ShopShopsComponentBiz shopShopsComponentBiz;
	@Autowired
	private ShopGoodsPromotionBiz shopGoodsPromotionBiz;
	
	public PageInfo<ShopShopsComponent> selectPageShopAdminList(Integer pageNo, Integer pageSize,Integer shopId) throws Exception {
		PageHelper.startPage(pageNo, pageSize);
		List<ShopShopsComponent> selectPageShopAdminList = shopShopsComponentBiz.selectPageShopAdminList(shopId);
		PageInfo<ShopShopsComponent> page = new PageInfo<ShopShopsComponent>(selectPageShopAdminList);
		return page;
	}

	@Override
	public void addShopsComponent(String token,ShopShopsComponent shopShopsComponent) throws Exception {
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		shopShopsComponent.setMerchantId(1);
		shopShopsComponent.setIndexRecommCount(10);
		shopShopsComponent.setCreateUserId(jwtInfo.getId());
		shopShopsComponent.setCreateTime(new Date());
		shopShopsComponentBiz.addShopShopsComponent(shopShopsComponent);
		List<ShopGoodsPromotion> shopGoodsPromotionList = new ArrayList<ShopGoodsPromotion>();
		for(int i=1;i<=10;i++) {
			ShopGoodsPromotion shopGoodsPromotion = new ShopGoodsPromotion();
			shopGoodsPromotion.setIndexRecommNum(i);
			shopGoodsPromotion.setCreateTime(new Date());
			shopGoodsPromotion.setShopId(shopShopsComponent.getShopId());
			shopGoodsPromotion.setMerchantId(1);
			shopGoodsPromotion.setComponentId(shopShopsComponent.getComponentId());
			shopGoodsPromotionList.add(shopGoodsPromotion);
		}
		shopGoodsPromotionBiz.addShopGoodsPromotionList(shopGoodsPromotionList);
	}

	@Override
	public ShopShopsComponent slelectById(Integer componentId) throws Exception {
		
		return shopShopsComponentBiz.selectByComponentId(componentId);
	}

	@Override
	public void updateShopsComponent(ShopShopsComponent shopShopsComponent) throws Exception {
			
		shopShopsComponentBiz.updateShopShopsComponent(shopShopsComponent);
	}

}
